const LRUCache = require("../template")

function testLRUCacheEdgeCases() {
  console.log(
    "1. 容量为 0 的缓存测试:",
    (() => {
      const cache = new LRUCache(0)
      cache.put(1, "a")
      const get1 = cache.get(1)
      const size = cache.size()
      return get1 === -1 && size === 0
    })()
  )

  console.log(
    "2. 负数 key 测试:",
    (() => {
      const cache = new LRUCache(2)
      cache.put(-1, "negative")
      cache.put(-2, "negative2")
      return cache.get(-1) === "negative" &&
             cache.get(-2) === "negative2"
    })()
  )

  console.log(
    "3. 字符串 key 测试:",
    (() => {
      const cache = new LRUCache(2)
      cache.put("key1", "value1")
      cache.put("key2", "value2")
      return cache.get("key1") === "value1" &&
             cache.get("key2") === "value2"
    })()
  )

  console.log(
    "4. 特殊值测试:",
    (() => {
      const cache = new LRUCache(3)
      cache.put(1, null)
      cache.put(2, undefined)
      cache.put(3, 0)
      return cache.get(1) === null &&
             cache.get(2) === undefined &&
             cache.get(3) === 0
    })()
  )

  console.log(
    "5. 对象值测试:",
    (() => {
      const cache = new LRUCache(2)
      const obj1 = { name: "test1" }
      const obj2 = { name: "test2" }
      cache.put(1, obj1)
      cache.put(2, obj2)
      const get1 = cache.get(1)
      const get2 = cache.get(2)
      return get1 === obj1 && get2 === obj2
    })()
  )

  console.log(
    "6. 大数值测试:",
    (() => {
      const cache = new LRUCache(2)
      cache.put(Number.MAX_SAFE_INTEGER, "max")
      cache.put(Number.MIN_SAFE_INTEGER, "min")
      return cache.get(Number.MAX_SAFE_INTEGER) === "max" &&
             cache.get(Number.MIN_SAFE_INTEGER) === "min"
    })()
  )

  console.log(
    "7. this上下文边界测试:",
    (() => {
      const edgeObj = {
        multiplier: 2,
        createCache: function(capacity) {
          const cache = new LRUCache(capacity * this.multiplier)
          cache.put(0, "zero")
          cache.put(-1, "negative")
          return cache.get(0) === "zero" && cache.get(-1) === "negative"
        }
      }
      return edgeObj.createCache(1) // 容量 2
    })()
  )

  console.log(
    "8. 复杂对象this绑定边界测试:",
    (() => {
      const edgeConfigObj = {
        config: { specialKeys: ["key1", "key2"] },
        createConfigCache: function() {
          const cache = new LRUCache(2)
          cache.put(this.config.specialKeys[0], "value1")
          cache.put(this.config.specialKeys[1], "value2")
          return cache.get("key1") === "value1" && cache.get("key2") === "value2"
        }
      }
      return edgeConfigObj.createConfigCache()
    })()
  )

  console.log(
    "9. 边界值一致性测试:",
    (() => {
      const cache = new LRUCache(3)
      cache.put(0, "zero")
      cache.put(null, "null")
      cache.put(undefined, "undefined")
      cache.put("", "empty")
      return cache.get(0) === "zero" &&
             cache.get(null) === "null" &&
             cache.get(undefined) === "undefined" &&
             cache.get("") === "empty"
    })()
  )

  console.log(
    "10. 特殊类型混合测试:",
    (() => {
      const cache = new LRUCache(4)
      cache.put(1, "number")
      cache.put("1", "string")
      cache.put(true, "boolean")
      cache.put({}, "object")
      return cache.get(1) === "number" &&
             cache.get("1") === "string" &&
             cache.get(true) === "boolean" &&
             cache.get({}) === -1 // 对象引用不同
    })()
  )
}

testLRUCacheEdgeCases()
